package com.aqie.easy.binarySearchTree;

import com.aqie.easy.structure.TreeNode;

/**
 * 108. 将有序数组转换为平衡二叉搜索树（右两子树的高度差的绝对值不能超过1）
 * 深度优先搜素
 *  >> 1 为什么和  /2
 */
public class SortedArrayToBST {
    public TreeNode sortedArrayToBST(int[] nums) {
        if (nums == null) return null;
        return toBST(nums,0, nums.length - 1);
    }

    private TreeNode toBST(int[] nums, int left, int right) {
        if(left > right) return null;
        int mid = left + ((right - left) / 2);
        TreeNode root = new TreeNode(nums[mid]);
        root.left = toBST(nums, left, mid - 1);
        root.right = toBST(nums, mid + 1, right);
        return root;
    }



    public static void main(String[] args) {
        int[] nums = {1,2,3,4,5};

    }
}
